package cn.com.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.com.entity.KeShi;
import cn.com.entity.YuYue;

public class YuYueDao {
	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	Session session;
	Transaction transaction;
	public List<YuYue> ckyuyue(){
		session=sessionFactory.openSession();
		String hql="from YuYue";
		Query query=session.createQuery(hql);
		List<YuYue> yylist=query.list();
		return yylist;
	}
	public boolean insertyuyue(YuYue yuyue){
		boolean b=false;
		session=sessionFactory.openSession();
		transaction=session.beginTransaction();
		if(yuyue!=null){
			session.save(yuyue);
			transaction.commit();
			b=true;
		}
		return b;
	}
	
	
	public YuYue getyuyue(int id){
		session=sessionFactory.openSession();
		YuYue yuyue=(YuYue)session.get(YuYue.class, id);
		return yuyue;
	}
	public boolean deleteyuyue(int id){
		boolean b=false;
		session=sessionFactory.openSession();
		YuYue yuyue=getyuyue(id);
		transaction=session.beginTransaction();
		if(yuyue!=null){
			session.delete(yuyue);
			transaction.commit();
			session.close();
			b=true;
		}
		return b;
	}
	public List<YuYue> getuserid(int userid){
		session=sessionFactory.openSession();
		String hql="from YuYue where userid=?";
		Query query=session.createQuery(hql);
		query.setInteger(0,userid);
		List<YuYue> yhlist=query.list();
		return yhlist;
	}
	public List<YuYue> getyishengid(int yishengid){
		session=sessionFactory.openSession();
		String hql="from YuYue where yishengid=?";
		Query query=session.createQuery(hql);
		query.setInteger(0,yishengid);
		List<YuYue> yslist=query.list();
		return yslist;
	}
}
